/*
 * Toedo
 * Copyright (C) 2009-2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package org.toedo.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.toedo.gui.views.NoteView;
import org.toedo.logging.Log;
import org.toedo.model.Note;

public class OpenNoteAction extends Action {

	private Note mNote;
	
	public OpenNoteAction(Note note) {
		mNote = note;
	}
	
	public void run() {
		try {				
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();							

			page.showView(NoteView.ID, mNote.getId().toString(), IWorkbenchPage.VIEW_ACTIVATE);								

		} catch (Exception e) {
			Log.getInstance(OpenNoteAction.class).warn(String.format("Unable to open note %s (%s).", mNote.getTitle(), e.getMessage()));			 //$NON-NLS-1$
		}
	}
	
}
